<template>
  <div class="tale-list-top">
    <el-form :model="formData" label-width="120px" ref="formRef">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="用户名" prop="username">
            <el-input v-model="formData.username" placeholder="请输入用户名" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="更新日期" props="updatetime">
            <el-date-picker
              v-model="formData.updatetime"
              type="datetimerange"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              style="width: 100%"
              value-format="YYYY-MM-DD HH:mm:ss"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <footer>
      <el-button type="warning" icon="Refresh" @click="resetForm">重置</el-button>
      <el-button type="primary" icon="Search" @click="handleSearchQuery">查询</el-button>
    </footer>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
const emit = defineEmits(['handleSearchQuery', 'resetAndQueryList'])

const formRef = ref()
const formData = reactive({
  username: '',
  updatetime: ''
})

const resetForm = () => {
  // 当表单数据过多的时候需要清除可以使用表单提供的实例方法进行清除
  formRef.value?.resetFields()
  // 清空表单数据的时候，重新获取所有表单数据
  emit('resetAndQueryList')
}
const handleSearchQuery = () => {
  emit('handleSearchQuery', formData)
}
</script>

<style lang="scss" scoped>
.tale-list-top {
  width: 100%;
  footer {
    display: flex;
    justify-content: flex-end;
  }
}
</style>
